<?php
/////////////////////////////////////////////////////////////////
// SpeedPHP中文PHP框架, Copyright (C) 2008 - 2010 SpeedPHP.com //
/////////////////////////////////////////////////////////////////

/**
 * spView 基础视图类
 */
class spView
{
    /**
     * 模板引擎实例
     */
    public $engine = null;
    /**
     * 模板是否已输出
     */
    public $displayed = FALSE;

    /**
     * 构造函数，进行模板引擎的实例化操作
     */
    public function __construct()
    {
        if (FALSE == $GLOBALS['G_SP']['view']['enabled']) return FALSE;
        if (FALSE != $GLOBALS['G_SP']['view']['auto_ob_start']) ob_start();
        $this->engine = spClass($GLOBALS['G_SP']['view']['engine_name'], null, $GLOBALS['G_SP']['view']['engine_path']);
        $this->engine->assign("G__C", $GLOBALS["__controller"]);
        $this->engine->assign("G__A", $GLOBALS["__action"]);
        $this->engine->assign("BACKURL", $_SERVER['HTTP_REFERER']);
        $configs = $GLOBALS['G_SP']['view']['config'];

        //设置视图引擎参数
        if (is_array($configs)) {
            $engine_vars = get_class_vars(get_class($this->engine));
            foreach ($configs as $key => $value) {
                if (array_key_exists($key, $engine_vars)) $this->engine->{$key} = $value;
            }
        }
        spAddViewFunction('T', array('spView', '__template_T'));
        spAddViewFunction('spUrl', array('spView', '__template_spUrl'));
        spAddViewFunction('spHUrl', array('spView', '__template_sphUrl'));
        spAddViewFunction('spTUrl', array('spView', '__template_spTUrl'));
        spAddViewFunction('zxsql', array('spView', '__template_zxsql'));
        spAddViewFunction('zxentrance', array('spView', '__template_zxentrance'));
        spAddViewFunction('zxunit', array('spView', '__template_unit'));
        spAddViewFunction('zxfindentrance', array('spView', '__template_zxfindentrance'));
        spAddViewFunction('zxfilter', array('spView', '__template_zxfilter'));
        spAddViewFunction('zxfind', array('spView', '__template_zxfind'));
        spAddViewFunction('zxfindAll', array('spView', '__template_zxfindAll'));
        spAddViewFunction('zxcolumnlist', array('spView', '__template_zxcolumnlist'));
        spAddViewFunction('zxcolumnlinkbyend', array('spView', '__template_zxcolumnlinkbyend'));
        spAddViewFunction('zxgetinfo', array('spView', '__template_zxgetinfo'));
        spAddViewFunction('zxadslist', array('spView', '__template_zxadslist'));
        spAddViewFunction('zxlinklist', array('spView', '__template_zxlinklist'));
        spAddViewFunction('zxcato1', array('spView', '__template_zxcato1'));
        spAddViewFunction('zxcato2', array('spView', '__template_zxcato2'));
        spAddViewFunction('zxsubcolumn', array('spView', '__template_zxsubcolumn'));
        spAddViewFunction('zxsubcolumn_c', array('spView', '__template_zxsubcolumn_c'));
        spAddViewFunction('zxValidator', array('spView', '__template_zxValidator'));
        spAddViewFunction('zxinfopage', array(spView, '__template_zxinfopage'));
        spAddViewFunction('zxinfotj', array(spView, '__template_zxinfotj'));
    }

    /**
     * 输出页面
     * @param tplname 模板文件路径
     */
    public function display($tplname)
    {
        $this->addfuncs();
        $this->displayed = TRUE;
        if ($GLOBALS['G_SP']['view']['debugging'] && SP_DEBUG) $this->engine->debugging = TRUE;
        $this->engine->display($tplname);
    }

    /**
     * 显示输出
     * @param tplname 模板文件路径
     */
    public function fetch($tplname)
    {
        $this->addfuncs();
        if ($contents = $this->engine->fetch($tplname)) {
            return $contents;
        } else {
            spError("模板文件{$tplname}不存在！");
        }
    }

    /**
     * 注册已挂靠的视图函数
     */
    public function addfuncs()
    {
        if (is_array($GLOBALS['G_SP']["view_registered_functions"]) &&
            method_exists($this->engine, 'register_function')
        ) {
            foreach ($GLOBALS['G_SP']["view_registered_functions"] as $alias => $func) {
                if (is_array($func) && !is_object($func[0])) $func = array(spClass($func[0]), $func[1]);
                $this->engine->register_function($alias, $func);
            }
        }
    }

    /**
     * 辅助spUrl的函数，让spUrl可在模板中使用。
     * @param params 传入的参数
     */
    public function __template_spUrl($params)
    {
        $controller = $GLOBALS['G_SP']["default_controller"];
        $action = $GLOBALS['G_SP']["default_action"];
        $args = array();
        $anchor = null;
        foreach ($params as $key => $param) {
            if ($key == $GLOBALS['G_SP']["url_controller"]) {
                $controller = $param;
            } elseif ($key == $GLOBALS['G_SP']["url_action"]) {
                $action = $param;
            } elseif ($key == 'anchor') {
                $anchor = $param;
            } else {
                $args[$key] = $param;
            }
        }
        if (TRUE == $GLOBALS['G_SP']['html']["enabled_zxadv"]) {
            return spUrl_htmladv($controller, $action, $args, $anchor);
        } else {
            return spUrl_htmladv($controller, $action, $args, $anchor);
        }
    }

    /**
     * 辅助T的函数，让T可在模板中使用。
     * @param params 传入的参数
     */
    public function __template_T($params)
    {
        return T($params['w']);
    }

    public function __template_sphUrl($params)
    {
        $url = $this->__template_spUrl($params);
        $back_url = WEB_ROOT . str_replace(dirname($url), "", $url);
        return $back_url;
    }

    public function __template_spTUrl($params)
    {
        $url = $this->__template_spUrl($params);
        $back_url = str_replace(dirname($url), "", $url);
        return $back_url;
    }

    public function __template_zxsql($params)
    {
        $db_rs = $obj_db = $tbl_name = $pk = $sql = $assign = null;
        $table = $params["table"];
        $pk = $params["pk"];
        $sql = $params["sql"];
        $assign = $params["assign"];
        $obj_db = spDB($table, $pk);
        if ($sql) {
            $db_rs = $obj_db->findSql($sql);
        }
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxentrance($params)
    {
        $assign = null;
        $assign = $params["assign"];
        $obj_db = spClass("entrance");
        $db_rs = $obj_db->getlist();
        if ($params["line"]) {
            $obj_line = spClass("entrance_line");
            foreach ($db_rs as $key => $val) {
                $db_rs[$key]["line_rs"] = $obj_line->getlist($val["id"]);
            }
        }
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_unit($params)
    {
        $assign = null;
        $assign = $params["assign"];
        $obj_db = spClass("entrance_unit");
        $db_rs = $obj_db->getlist();
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxfindentrance($params)
    {
        $assign = null;
        $assign = $params["assign"];
        $entid = $params["entid"];
        $obj_db = spClass("entrance");
        $db_rs = $obj_db->getinfoById($entid);
        if ($db_rs && $params["line"]) {
            $obj_line = spClass("entrance_line");
            $db_rs["line_rs"] = $obj_line->getlist($db_rs["id"]);
        }
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxfilter($params)
    {
        $assign = null;
        $assign = $params["assign"];
        $obj_db = spClass("articlefilter");
        if (intval($params["fid"])) {
            $db_rs = $obj_db->getSublist($params["cid"], $params["fid"]);
        } else {
            $db_rs = $obj_db->getToplist($params["cid"]);
            if ($db_rs) {
                foreach ($db_rs as $key => $val) {
                    $db_rs[$key]["sub_rs"] = $obj_db->getSublist($params["cid"], $val["pc_id"]);
                }
            }
        }
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxfind($params)
    {
        $db_rs = $this->__template_get_rs($params);
        $assign = $params["assign"];
        $this->engine->assign($assign, $db_rs[0]);
    }

    public function __template_zxfindAll($params)
    {
        $db_rs = $this->__template_get_rs($params);
        $assign = $params["assign"];
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxcolumnlinkbyend($params)
    {
        $db_rs = $obj_db = $sid = $assign = $return = null;
        if (!intval($params['sid'])) return;
        $assign = $params["assign"];
        $sid = intval($params['sid']);
        $obj_db = spDB("articlestyle", "sid");
        $sql = "select sid,parentid,sname from " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle where sid = $sid order by columnorder asc, sid asc";
        if ($temp_rs = $obj_db->findSql($sql)) {
            $db_rs[] = $temp_rs[0];
            $tempdata['sid'] = $temp_rs[0]['parentid'];
            $tempdata['return'] = 1;
            if (intval($tempdata['sid'])) {
                $db_rs[] = $this->__template_zxcolumnlinkbyend($tempdata);
            }
        }
        if (intval($params['return'])) {
            return $db_rs[0];
        } else {
            $db_rs = array_reverse($db_rs);
            $this->engine->assign($assign, $db_rs);
        }
    }

    public function __template_zxcolumnlist($params)
    {
        $db_rs = $obj_db = $tbl_name = $pk = $cldisplay = $assign = $limit = null;
        $cldisplay = (string)$params["display"];
        $pk = intval($params["pk"]);
        $condition = "webshow = 1";
        if ($cldisplay . "zx" == "zx") {
            //$condition = "";
        } elseif (intval($cldisplay) == 0) {
            $condition .= " and frontdisplay = 0";
        } else {
            $condition .= " and frontdisplay = 1";
        }
        if ($params['parentid'] . "zx" != "zx") {
            $condition .= " and parentid = " . intval($params[parentid]);
        } else {
            $condition .= " and parentid <> 0";
        }
        if ($pk) {
            $condition .= " and sid = $pk";
        }
        if ($params['condition_str']) {
            $condition .= " and " . $params['condition_str'];
        }
        $limit = intval($params["limited"]) ? "limit 0, " . intval($params["limited"]) : "";
        $assign = $params["assign"];
        $obj_db = spDB("articlestyle", "sid");
        $obj_pdb = spDB("article", "pid");
        $sql = "select * from " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle where $condition order by columnorder asc, sid asc $limit";
        if ($db_rs = $obj_db->findSql($sql)) {
            foreach ($db_rs as $key => $val) {
                if ($val['outlink']) {
                    $db_rs[$key]['turl'] = strtolower(substr($val['outlink'], 0, 7)) == "http://" ? $val['outlink'] : WEB_ROOT . "/" . $val['outlink'];
                    continue;
                }
                if ($val['islist'] == 0) {
                    if ($obj_pdb_rs = $obj_pdb->findSql("select pid, picurlfile, picurlpath from " . $GLOBALS['spConfig']['db']['prefix'] . "articles where ptype = " . $val['sid'])) {
                        $db_rs[$key]['turl'] = spUrl("main", "cdetail", array("id" => $obj_pdb_rs[0]['pid']));
                        $db_rs[$key]["thumb"] = $obj_pdb_rs[0]['picurlfile'] ? $obj_pdb_rs[0]['picurlpath'] . "thumb_" . $obj_pdb_rs[0]['picurlfile'] : "";
                		$db_rs[$key]["pic"] = $obj_pdb_rs[0]['picurlfile'] ? $obj_pdb_rs[0]['picurlpath'] . $obj_pdb_rs[0]['picurlfile'] : "";
                    } else {
                        unset($db_rs[$key]);
                    }
                } else {
                    $db_rs[$key]['turl'] = spUrl("main", "clist", array("id" => $val['sid']));
                }
            }
        }
        if (intval($params["debug"])) {
            echo $sql;
            print_r($db_rs);
        }
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxgetinfo($params)
    {
        $db_rs = $top = $index = $pid = $sub = $short = $sort = $start = $limit = $cldisplay = $extfield = $entrance_id = $is_entrance = $is_entranceline = $assign = null;
        $extfield = intval($params["extfield"]);
        $is_entrance = intval($params['is_entrance']);
        $is_entranceline = intval($params['is_entranceline']);
        $isunit = intval($params['isunit']);
        $unit_format = intval($params['isunit_format']);
        $isvideo = intval($params['isvideo']);
        $table_article = $GLOBALS['spConfig']['db']['prefix'] . "articles";
        $condition = "$table_article.ishide = 0";
        if (intval($params['entrance_id'])) {
            $condition .= " and $table_article.entrance_id = " . intval($params[entrance_id]);
        }
        if (intval($params['cid'])) {
            $condition .= " and $table_article.ptype = " . intval($params[cid]);
        }
        if (intval($params['f_cid'])) {
            $condition .= " and " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.parentid = " . intval($params[f_cid]);
        }
        if (intval($params['pcid'])) {
            $condition .= " and $table_article.pc_id = " . intval($params[pcid]);
        }
        if (intval($params['top'])) {
            $condition .= " and $table_article.top = " . intval($params['top']);
        }
        if (intval($params['recomd'])) {
            $condition .= " and $table_article.recomd = " . intval($params['recomd']);
        }
        if (intval($params['specrecomd'])) {
            $condition .= " and $table_article.specrecomd = " . intval($params['specrecomd']);
        }
        if (intval($params['stj_news'])) {
            $condition .= " and $table_article.stj_news = 1";
        }
        if (intval($params['stj_hot'])) {
            $condition .= " and $table_article.stj_hot = 1";
        }
        if (intval($params['isindex'])) {
            $condition .= " and $table_article.isindex = " . intval($params['isindex']);
        }
        if (intval($params['pid'])) {
            $condition .= " and $table_article.pc_id = " . intval($params['pid']);
        }
        if (intval($params['id'])) {
            $condition .= " and $table_article.pid = " . intval($params['id']);
        }
        if ($params['locate']) {
            $condition .= " and (";
            $condition .= "if(" . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.freeother <> '', locate(" . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.freeother, '" . $params[locate] . "'), 0)";
            $condition .= " or ";
            $condition .= "if(" . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.freeother2 <> '', locate(" . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.freeother2, '" . $params[locate] . "'), 0)";
            $condition .= " or ";
            $condition .= "if(" . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.freeother3 <> '', locate(" . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.freeother3, '" . $params[locate] . "'), 0)";
            $condition .= ")";
        }
        if ($params['sub'] . "zx" != "zx" && intval($params['sub'])) {
            $condition .= " and $table_article.subproduct = " . intval($params['sub']);
        }
        if ($params['filter']) {
            $filter = explode(",", $params['filter']);
            $condition .= " and (1";
            foreach ($filter as $k => $v) {
                $condition .= " and find_in_set(" . $v . ", $table_article.filter2_id)";
            }
            $condition .= ")";
        }
        if ($params['condition_str']) {
            $condition .= " and " . $params['condition_str'];
        }
        $short = intval($params['short']) ? intval($params['short']) : 1000000;
        if (intval($params['limited'])) {
            $limit = "limit " . intval($params['start']) . "," . intval($params['limited']);
        }
        $sort = $params['sort'];
        if ($sort) {
            $sort = "order by $sort";
        } else {
            $sort = "order by $table_article.`top` desc, $table_article.`recomd` desc, $table_article.stj_hot desc, $table_article.stj_news desc, $table_article.stj_soldout asc, $table_article.`specrecomd` desc, $table_article.`order` asc, $table_article.`status` desc, $table_article.`posttime` desc, $table_article.`pid` desc";
        }
        $assign = $params["assign"];
        $obj_article = spClass("article");
        $obj_video = spClass("article_video");
        $obj_extval = spClass("article_extval");
        $obj_ent = spClass("entrance");
        $obj_line = spClass("entrance_line");
        $obj_column = spClass("articlestyle");
        if ($isunit && intval($params[cid])) {
            if ($unit_from_rs = $obj_column->join("hnyn_entrance_unit", "hnyn_entrance_unit.id = hnyn_articlestyle.price1_unit")->find(array("hnyn_articlestyle.sid" => intval($params[cid]), "hnyn_articlestyle.isprice" => 3, "hnyn_articlestyle.price1_unit >" => 0), null, "hnyn_entrance_unit.rate")) {
                $unit_from_rate = floatval($unit_from_rs["rate"]);
            }
        }
        if ($params['debug']) $obj_article->debug(1);
        $db_rs = $obj_article->findSql("select " . $GLOBALS['spConfig']['db']['prefix'] . "articles.*, " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.sname, ". $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.sname_en, " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.islist from " . $GLOBALS['spConfig']['db']['prefix'] . "articles inner join " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle on " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.sid = " . $GLOBALS['spConfig']['db']['prefix'] . "articles.ptype where $condition $sort $limit");
        if ($db_rs) {
            foreach ($db_rs as $key => $val) {
                $ent_rs = $obj_ent->findByPk($val["entrance_id"], "name");
                $db_rs[$key]["ent_name"] = $ent_rs["name"];
                if ($val["link"] && $val["link"] != 'NULL') {
                    $db_rs[$key]["turl"] = str_replace("__url__", $_SERVER['HTTP_HOST'] . WEB_ROOT, strtolower($val['link']));
                } else {
                    $db_rs[$key]["turl"] = spUrl("main", "cdetail", array("id" => $val['pid']));
                }
                $db_rs[$key]["thumb"] = $val['picurlfile'] ? $val['picurlpath'] . "thumb_" . $val['picurlfile'] : "images/blank.png";
                $db_rs[$key]["pic"] = $val['picurlfile'] ? $val['picurlpath'] . $val['picurlfile'] : "images/blank.png";
                $db_rs[$key]["short"] = $db_rs[$key]["short"] == 'NULL' ? "" : $db_rs[$key]["short"];
                $db_rs[$key]["sdesc"] = $this->removehtml($val['description'], $short);
                $db_rs[$key]["ftime"] = date("Y-m-d", strtotime($val['posttime']));
                $db_rs[$key]["description"] = str_replace('/upload/', URL_ROOT.'/upload/', $val['description']);
                if ($unit_from_rate)
                    $db_rs[$key]["price_unit"] = intval($val["price"] / $unit_from_rate);
                if ($unit_format) {
                    $db_rs[$key]["price"] = number_format($db_rs[$key]["price"]);
                    if ($db_rs[$key]["price_unit"])
                        $db_rs[$key]["price_unit"] = number_format($db_rs[$key]["price_unit"]);
                }
                if ($val["entrance_id"]) {
                    $ent_rs = $obj_ent->findByPk($val["entrance_id"], "name, mark, unit, unit_en");
                    $db_rs[$key]["ent_name"] = $ent_rs["name"];
                    $db_rs[$key]["ent_rs"] = $ent_rs;
                    if (!$val["link"] || $val["link"] == "NULL")
                        $db_rs[$key]["turl"] = WEB_ROOT . "/" . $ent_rs["mark"] . substr($db_rs[$key]["turl"], strrpos($db_rs[$key]["turl"], "/"));
                }
                if ($val['extinput']) {
                    $db_rs[$key]["ext"] = unserialize($val['extinput']);
                }
                if ($is_entranceline) {
                    $line_rs = $obj_line->findByPk($val["entrance_line_id"], "name");
                    $db_rs[$key]["line_name"] = $line_rs["name"];
                }
                if ($extfield)
                    $db_rs[$key]["extfield"] = $obj_extval->extval_get_mark($val['pid']);
                if($isvideo){
                    $video_rs = $obj_video->getShowInfoFromArticle($val['pid'], 1);
                    $db_rs[$key]["videourl"] = $video_rs["filepath"];
                }
            }
        }
        if ($params['limited'] == "1")
            $db_rs = $db_rs[0];
        if (intval($params["isreturn"]))
            return $db_rs;
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxadslist($params)
    {
        $db_rs = $limit = $cldisplay = $assign = null;
        $info_table = $GLOBALS['spConfig']['db']['prefix'] . "ad_info";
        $group_table = $GLOBALS['spConfig']['db']['prefix'] . "ad_group";
        $unit_table = $GLOBALS['spConfig']['db']['prefix'] . "entrance_unit";
        $condition1 = "$info_table.is_del = 0";
        $condition2 = "1";
        if (intval($params['gid'])) {
            $condition2 .= " and $group_table.groupid = " . intval($params[gid]);
        }
        if (intval($params['cid'])) {
            $condition2 .= " and $group_table.columnid = " . intval($params[cid]);
        }
        if ($params['code']) {
            $condition2 .= " and $group_table.code = '" . $params[code] . "'";
        }
        $obj_ag = spClass("ad_group");
        $ag_rs = $obj_ag->find($condition2, null, "$group_table.isunit, $group_table.is_linkarticle, $group_table.show_num");
        if (intval($params['limited'])) {
            $limitstr = "limit " . intval($params['start']) . "," . intval($params['limited']);
        } else {
            $limitstr = "limit " . intval($params['start']) . ", " . intval($ag_rs[show_num]);
        }
        $assign = $params["assign"];
        $obj_ad = spClass("ad_info");
        if ($ag_rs["isunit"]) {
            $db_rs = $obj_ad->join($group_table, "$group_table.groupid = $info_table.group_id")->join($unit_table, "$info_table.unit_id = $unit_table.id")->findAll("$condition1 and $condition2", "$info_table.sort asc, $info_table.ads_id desc", "$info_table.*, $unit_table.mark as unit_mark, $unit_table.name as unit_name");
        } else {
            $db_rs = $obj_ad->join($group_table, "$group_table.groupid = $info_table.group_id")->findAll("$condition1 and $condition2", "$info_table.sort asc, $info_table.ads_id desc", "$info_table.*");
        }
        if ($db_rs) {
            foreach ($db_rs as $key => $val) {
                if ($ag_rs["is_linkarticle"] && $val["article_id"]) {
                    $db_rs[$key]["article_rs"] = array_shift($this->__template_zxgetinfo(array("id" => $val["article_id"], "is_entranceline" => 1, "isreturn" => 1)));
                }
                $db_rs[$key]['name'] = $val["title"];
                $db_rs[$key]['thumb'] = $val['pathurl'] . "thumb_" . $val['pathfile'];
                $db_rs[$key]['pic'] = $val['pathurl'] . $val['pathfile'];
                $db_rs[$key]['turl'] = str_replace("__url__", $_SERVER['HTTP_HOST'] . WEB_ROOT, strtolower($val['ads_href']));
            }
        }
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxlinklist($params)
    {
        $db_rs = $limit = $cldisplay = $assign = null;
        $condition = "is_verify = 1";
        $assign = $params["assign"];
        if (intval($params['limited'])) {
            $limitstr = "limit " . intval($params['start']) . "," . intval($params['limited']);
        }
        $obj_ag = spDB("link", "id");
        $db_rs = $obj_ag->findSql("select * from " . $GLOBALS['spConfig']['db']['prefix'] . "links where $condition $limitstr");
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxcato1($params)
    {
        $db_rs = $limit = $cldisplay = $assign = null;
        $condition = "1 = 1";
        if (intval($params['cid'])) {
            $condition .= " and markid = " . intval($params[cid]);
        }
        if ($params['fid'] . "a" != "a") {
            $condition .= " and fid = " . intval($params[fid]);
        }
        if (intval($params['is_recommend'])) {
            $condition .= " and is_recommend = " . intval($params[is_recommend]);
        }
        if (intval($params['limited'])) {
            $limit = " limit " . intval($params['start']) . "," . intval($params['limited']);
        }
        $assign = $params["assign"];
        $obj_ag = spDB("articlecato", "pc_id");
        if ($db_rs = $obj_ag->findSql("select * from " . $GLOBALS['spConfig']['db']['prefix'] . "articlescato where $condition order by `is_recommend` desc, `order` asc $limit")) {
            foreach ($db_rs as $key => $val) {
                $db_rs[$key]['thumb'] = $val['picpath'] . "thumb_" . $val['picfile'];
                $db_rs[$key]['pic'] = $val['picpath'] . $val['picfile'];
                $db_rs[$key]["turl"] = spUrl("main", "clist", array("id" => intval($params['cid']), "pid" => $val['pc_id']));
            }
        }
        $this->engine->assign($assign, $db_rs);
    }
    
    public function __template_zxcato2($params){
    	$db_rs = $limit = $cldisplay = $assign = null;
        $condition = "fid = 0";
        if (intval($params['cid'])) {
            $condition .= " and markid = " . intval($params[cid]);
        }
        if (intval($params['is_recommend'])) {
            $condition .= " and is_recommend = " . intval($params[is_recommend]);
        }
        if (intval($params['limited'])) {
            $limit = " limit " . intval($params['start']) . "," . intval($params['limited']);
        }
        $assign = $params["assign"];
        $obj_ag = spDB("articlecato", "pc_id");
        $obj_cato = spClass("articlecato");
        if ($db_rs = $obj_ag->findSql("select * from " . $GLOBALS['spConfig']['db']['prefix'] . "articlescato where $condition order by `is_recommend` desc, `order` asc $limit")) {
            foreach ($db_rs as $key => $val) {
                $db_rs[$key]['thumb'] = $val['picpath'] . "thumb_" . $val['picfile'];
                $db_rs[$key]['pic'] = $val['picpath'] . $val['picfile'];
                $db_rs[$key]["turl"] = spUrl("main", "clist", array("id" => intval($params['cid']), "pid" => $val['pc_id']));
            	$sub_rs = $obj_cato->findAll(array("fid"=>$val["pc_id"]), "`is_recommend` desc, `order` asc");
            	if($sub_rs){
            		foreach($sub_rs as $k => $v){
            			$sub_rs[$k]["turl"] = spUrl("main", "clist", array("id" => intval($params['cid']), "pid" => $v['pc_id']));
            		}
            	}
            	$db_rs[$key]["sub_rs"] = $sub_rs;
            }
        }
        $this->engine->assign($assign, $db_rs);
    }

    private function __template_get_rs($params)
    {
        $db_rs = $obj_db = $table = $pk = $condition = $sort = $field = $jointable = $joincondition = $joinmode = $join = $assign = null;
        extract($params);
        $condition = $condition ? " and " . $condition : "";
        $sort = $sort ? "order by " . $sort : "";
        $field = $field ? $field : "*";
        $obj_db = spDB($table, $pk);
        if ($jointable && $joincondition && $joinmode) {
            $join = "$joinmode join $jointable on $joincondition";
        }
        $sql = "select $field from " . $GLOBALS['spConfig']['db']['prefix'] . "$table $join where 1 = 1 $condition $sort";
        $db_rs = $obj_db->findSql($sql);
        return $db_rs;
    }

    public function __template_zxsubcolumn($params)
    {
        $db_rs = $limit = $sid = $assign = null;
        $condition = "1";
        $assign = $params["assign"];
        if (intval($params['cid'])) {
            $condition .= " and ptype = " . intval($params['cid']);
        }
        if (intval($params['sid'])) {
            $condition .= " and subproduct = " . intval($params['sid']);
        }
        if ($params['condition_str']) {
            $condition .= " and " . $params['condition_str'];
        }
        if (intval($params['limited'])) {
            $limitstr = "limit " . intval($params['start']) . "," . intval($params['limited']);
        }
        $sort = $params['sort'];
        if ($sort) {
            $sort = "order by $sort";
        } else {
            $sort = "order by `specrecomd` desc, `recomd` desc, `top` desc, `order` asc, `posttime` desc, `pid` desc";
        }
        $obj_ag = spDB("articles", "pid");
        if ($db_rs = $obj_ag->findSql("select * from " . $GLOBALS['spConfig']['db']['prefix'] . "articles where $condition $sort $limitstr")) {
            foreach ($db_rs as $key => $val) {
                $db_rs[$key]["thumb"] = $val['picurlfile'] ? $val['picurlpath'] . "thumb_" . $val['picurlfile'] : "";
                $db_rs[$key]["pic"] = $val['picurlfile'] ? $val['picurlpath'] . $val['picurlfile'] : "";
                $db_rs[$key]['turl'] = spUrl("main", "cdetail", array("id" => $val['pid']));
            }
        }
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxsubcolumn_c($params)
    {
        $db_rs = $limit = $sid = $assign = null;
        $condition = "1";
        $assign = $params["assign"];
        if (intval($params['cid'])) {
            $condition .= " and ptype = " . intval($params['cid']);
        }
        if (intval($params['sid'])) {
            $condition .= " and subproduct = " . intval($params['sid']);
        }
        if ($params['condition_str']) {
            $condition .= " and " . $params['condition_str'];
        }
        if (intval($params['limited'])) {
            $limitstr = "limit " . intval($params['start']) . "," . intval($params['limited']);
        }
        $sort = $params['sort'];
        if ($sort) {
            $sort = "order by $sort";
        } else {
            $sort = "order by `top` desc, `order` asc, `posttime` desc, `pid` desc";
        }
        $obj_ag = spDB("article", "pid");
        if ($params['debug']) $obj_ag->debug(1);
        if ($db_rs = $obj_ag->findSql("select " . $GLOBALS['spConfig']['db']['prefix'] . "articles.*, " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.parentid from " . $GLOBALS['spConfig']['db']['prefix'] . "articles inner join " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle on " . $GLOBALS['spConfig']['db']['prefix'] . "articles.subproduct = " . $GLOBALS['spConfig']['db']['prefix'] . "articlestyle.sid where $condition $sort $limitstr")) {
            foreach ($db_rs as $key => $val) {
                $db_rs[$key]["thumb"] = $val['picurlfile'] ? $val['picurlpath'] . "thumb_" . $val['picurlfile'] : "";
                $db_rs[$key]["pic"] = $val['picurlfile'] ? $val['picurlpath'] . $val['picurlfile'] : "";
                $db_rs[$key]['turl'] = spUrl("main", "cdetail", array("id" => $val['pid']));
                if ($val['extinput']) {
                    $db_rs[$key]["ext"] = unserialize($val['extinput']);
                }
            }
        }
        $this->engine->assign($assign, $db_rs);
    }

    public function __template_zxValidator($params)
    {
        $model = null;
        $model = $params["model"];
        $obj = spClass($model);
        echo $obj->getValidatorJS();
    }

    public function __template_zxinfopage($params)
    {
        $id = intval($params["id"]);
        $nowpage = max(intval($params["p"]), 1);
        $contents = $params["contents"];
        $arr = explode('<!--pagebreak-->', $contents);
        $total = count($arr);
        $pdiv = '<br class=clear /><ul id=fenye>';
        $pdiv .= "<li>总{$nowpage}/{$total}页</li>";

        for ($i = 1; $i <= $total; $i++) {
            $url = spUrl("main", "cdetail", array('id' => $id, 'p' => $i));
            $pdiv .= "<li><a href=\"{$url}\">{$i}</a></li>";
        }

        $pdiv .= '</ul><br class=clear />';    //输出内容
        echo $arr[$nowpage - 1];    //不分页则不显示分页列表
        if ($total <= 1) $pdiv = '';    //输出分页列表
        echo $pdiv;
    }

    public function __template_zxinfotj($params)
    {
        $id = intval($params["pid"]);
        $count = intval($params["count"]);
        $assign = $params["assign"];
        $obj_article = spClass("article");
        $obj_cato = spClass("articlecato");
        $now_rs = $obj_article->find(array("pid" => $id));
        $sort = "hnyn_articles.`top` desc, hnyn_articles.`recomd` desc, hnyn_articles.stj_hot desc, hnyn_articles.stj_news desc, hnyn_articles.stj_soldout asc, hnyn_articles.`specrecomd` desc, hnyn_articles.`order` asc, hnyn_articles.`status` desc, hnyn_articles.`posttime` desc, hnyn_articles.`pid` desc";
        $article_id = array("0");
        $now_count = 0;
        if ($now_rs["pc_id"]) {
            $condition = array("pc_id" => $now_rs["pc_id"]);
            $cato_rs = $obj_cato->find($condition, null, "fid");
            if ($cato_rs["fid"]) {
                $conditionstr = "hnyn_articles.pid <> $id and hnyn_articlescato.fid = {$cato_rs["fid"]}";
                $conditionstr .= " and hnyn_articles.pid not in(" . implode(",", $article_id) . ")";
                if ($article_rs = $obj_article->join("hnyn_articlescato")->findAll($conditionstr, $sort, "hnyn_articles.*", null, $count)) {
                    foreach ($article_rs as $val) {
                        $article_id[] = $val["pid"];
                    }
                }
                $now_count = count($article_id) - 1;
            }
            if ($now_count <= $count) {
                $conditionstr = "hnyn_articles.pid <> $id and hnyn_articlescato.pc_id = {$now_rs["pc_id"]}";
                $conditionstr .= " and hnyn_articles.pid not in(" . implode(",", $article_id) . ")";
                if ($article_rs = $obj_article->join("hnyn_articlescato")->findAll($conditionstr, $sort, "hnyn_articles.*", null, $count)) {
                    foreach ($article_rs as $val) {
                        $article_id[] = $val["pid"];
                    }
                }
                $now_count = count($article_id) - 1;
            }
        }
        if ($now_count <= $count) {
            $conditionstr = "hnyn_articles.pid <> $id and hnyn_articles.ptype = {$now_rs["ptype"]}";
            $conditionstr .= " and hnyn_articles.pid not in(" . implode(",", $article_id) . ")";
            if ($article_rs = $obj_article->findAll($conditionstr, $sort, "hnyn_articles.*", null, $count)) {
                foreach ($article_rs as $val) {
                    $article_id[] = $val["pid"];
                }
            }
            $now_count = count($article_id) - 1;
        }
        if ($article_rs) {
            foreach ($article_rs as $key => $val) {
                $article_rs[$key]["turl"] = $val["link"] && $val["link"] != 'NULL' ? $val["link"] : spUrl("main", "cdetail", array("id" => $val['pid']));
                $article_rs[$key]["thumb"] = $val['picurlfile'] ? $val['picurlpath'] . "thumb_" . $val['picurlfile'] : "";
                $article_rs[$key]["pic"] = $val['picurlfile'] ? $val['picurlpath'] . $val['picurlfile'] : "";
                $article_rs[$key]["ftime"] = date("Y-m-d", strtotime($val['posttime']));
            }
        }
        $this->engine->assign($assign, $article_rs);
    }

    private function removehtml($str, $length)
    {
        import("Common.php");
        if (!empty($str)) {
            $str = strip_tags($str, '<br><br />');
            $str = Common::utf8_substr(Common::trimHtml(strip_tags($str)), 0, intval($length), "");
        }
        return $str;
    }
}

/**
 * spHtml
 * 静态HTML生成类
 */
class spHtml
{
    private $spurls = null;

    /**
     * 生成单个静态页面
     *
     * @param spurl spUrl的参数
     * @param alias_url 生成HTML文件的名称，如果不设置alias_url，将使用年月日生成目录及随机数为文件名的形式生成HTML文件。
     * @param update_mode    更新模式，默认2为同时更新列表及文件
     * 0是仅更新列表
     * 1是仅更新文件
     */
    public function make($spurl, $alias_url = null, $update_mode = 2)
    {
        if (1 == spAccess('r', 'sp_html_making')) {
            $this->spurls[] = array($spurl, $alias_url);
            return;
        }
        @list($controller, $action, $args, $anchor) = $spurl;
        if (TRUE != $GLOBALS['G_SP']['html']['enabled_zxadv'] && $url_item = spHtml::getUrl($controller, $action, $args, $anchor, TRUE)) {
            @list($baseuri, $realfile) = $url_item;
            $update_mode = 1;
        } else {
            $file_root_name = ('' == $GLOBALS['G_SP']['html']['file_root_name'] || './' == $GLOBALS['G_SP']['html']['file_root_name']) ? $GLOBALS['G_SP']['html']['file_root_name'] : $GLOBALS['G_SP']['html']['file_root_name'] . '/';
            if (null == $alias_url) {
                $filedir = $file_root_name . date('Y/n/d') . '/';
                $filename = substr(time(), 3, 10) . substr(mt_rand(100000, substr(time(), 3, 10)), 4) . ".html";
            } else {
                $filedir = $file_root_name . dirname($alias_url) . '/';
                $filename = basename($alias_url);
            }
            $baseuri = rtrim(dirname($GLOBALS['G_SP']['url']["url_path_base"]), '/\\') . "/" . $filedir . $filename;
            $realfile = APP_PATH . "/" . $filedir . $filename;
        }
        if (0 == $update_mode or 2 == $update_mode) spHtml::setUrl($spurl, $baseuri, $realfile);
        if (1 == $update_mode or 2 == $update_mode) {
            $oralcode = (TRUE == $GLOBALS['G_SP']['html']['enabled_zxadv'] ? 1 : 0);
            $remoteurl = 'http://' . $_SERVER["SERVER_NAME"] . ':' . $_SERVER['SERVER_PORT'] .
                '/' . ltrim(spUrl($controller, $action, $args, $anchor, TRUE, $oralcode), '/\\');
            $cachedata = file_get_contents($remoteurl);
            if (FALSE === $cachedata) {
                $cachedata = $this->curl_get_file_contents($remoteurl);
                if (FALSE === $cachedata) spError("无法从网络获取页面数据，请检查：<br />1. spUrl生成地址是否正确！<a href='{$remoteurl}' target='_blank'>点击这里测试</a>。<br />2. 设置php.ini的allow_url_fopen为On。<br />3. 检查是否防火墙阻止了APACHE/PHP访问网络。<br />4. 建议安装CURL函数库。");
            }
            __mkdirs(dirname($realfile));
            file_put_contents($realfile, $cachedata);
        }
    }

    public function directmake($spurl, $alias_url = null, $update_mode = 2, $root = null, $cache = 'data', $static = 'static', $access = 'index.php')
    {
        if ($access) {
            $oralbase = $GLOBALS['G_SP']['url']["url_path_base"];
            $GLOBALS['G_SP']['url']["url_path_base"] = '/' . $access;
        }
        if ($cache) {
            $oralcache = $GLOBALS['G_SP']['sp_cache'];
            $GLOBALS['G_SP']['sp_cache'] = $root . DS . $cache;
        }
        if (1 == spAccess('r', 'sp_html_making')) {
            $this->spurls[] = array($spurl, $alias_url);
            return;
        }
        @list($controller, $action, $args, $anchor) = $spurl;
        if ($url_item = spHtml::getUrl($controller, $action, $args, $anchor, TRUE)) {
            @list($baseuri, $realfile) = $url_item;
            $update_mode = 1;
        } else {
            $file_root_name = $root;
            if (null == $alias_url) {
                $filedir = '/' . $file_root_name . '/' . date('Y/n/d') . '/';
                $filename = substr(time(), 3, 10) . substr(mt_rand(100000, substr(time(), 3, 10)), 4) . ".html";
            } else {
                $filedir = '/' . $file_root_name . '/' . $static . dirname($alias_url) . '/';
                $filename = basename($alias_url);
            }
            $baseuri = $filedir . $filename;
            $realfile = APP_PATH . "/" . $filedir . $filename;
        }
        if (0 == $update_mode or 2 == $update_mode) spHtml::setUrl($spurl, $baseuri, $realfile);
        if (1 == $update_mode or 2 == $update_mode) {
            $remoteurl = 'http://' . $_SERVER["SERVER_NAME"] . ':' . $_SERVER['SERVER_PORT'] .
                '/' . $root . '/' . ltrim(spUrl($controller, $action, $args, $anchor, TRUE), '/\\');
            $cachedata = file_get_contents($remoteurl);
            if (FALSE === $cachedata) {
                $cachedata = $this->curl_get_file_contents($remoteurl);
                if (FALSE === $cachedata) spError("无法从网络获取页面数据，请检查：<br />1. spUrl生成地址是否正确！<a href='{$remoteurl}' target='_blank'>点击这里测试</a>。<br />2. 设置php.ini的allow_url_fopen为On。<br />3. 检查是否防火墙阻止了APACHE/PHP访问网络。<br />4. 建议安装CURL函数库。");
            }

            __mkdirs(dirname($realfile));
            file_put_contents($realfile, $cachedata);
        }
        if ($access) {
            $GLOBALS['G_SP']['url']["url_path_base"] = $oralbase;
        }
        if ($cache) {
            $GLOBALS['G_SP']['sp_cache'] = $oralcache;
        }
    }

    /**
     * 当file_get_contents失效时，程序将调用CURL函数来进行网络数据获取
     * @param url 访问地址
     */
    function curl_get_file_contents($url)
    {
        if (!function_exists('curl_init')) return FALSE;
        $c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $url);
        $contents = curl_exec($c);
        curl_close($c);
        if (FALSE === $contents) return FALSE;
        return $contents;
    }

    /**
     * 批量生成静态页面
     * @param spurls 数组形式，每项是一个make()的全部参数
     */
    public function makeAll($spurls)
    {
        foreach ($spurls as $single) {
            list($spurl, $alias_url) = $single;
            $this->make($spurl, $alias_url, 0);
        }
        foreach ($spurls as $single) {
            list($spurl, $alias_url) = $single;
            $this->make($spurl, $alias_url, 1);
        }
    }

    public function zxmakeAll($spurls, $mode = 2)
    {
        if ($mode = 0 || $mode = 2) {
            foreach ($spurls as $single) {
                list($spurl, $alias_url) = $single;
                $this->make($spurl, $alias_url, 0);
            }
        }
        if ($mode = 1 || $mode = 2) {
            foreach ($spurls as $single) {
                list($spurl, $alias_url) = $single;
                $this->make($spurl, $alias_url, 1);
            }
        }
    }

    public function start()
    {
        spAccess('w', 'sp_html_making', 1);
        $this->spurls = null;
    }

    public function commit()
    {
        spAccess('c', 'sp_html_making');
        $this->makeAll($this->spurls);
    }

    /**
     * 获取url的列表程序，可以按配置开启是否检查文件存在
     * @param controller    控制器名称，默认为配置'default_controller'
     * @param action    动作名称，默认为配置'default_action'
     * @param args    传递的参数，数组形式
     * @param anchor    跳转锚点
     * @param force_no_check    是否检查物理文件是否存在
     */

    public function getUrl($controller = null, $action = null, $args = null, $anchor = null, $force_no_check = FALSE)
    {
        if ($url_list = spAccess('r', 'sp_url_list')) {
            $url_list = explode("\n", $url_list);
            /*
            统一将传导过来的参数转化成字符串形式 start
            zx 2012-04-19
            */
            if (!empty($args)) {
                foreach ($args as $key => $val) {
                    $args[$key] = (string)$val;
                }
            }
            /*
            统一将传导过来的参数转化成字符串形式 end
            */
            $args_en = !empty($args) ? json_encode($args) : "";
            $url_input = "{$controller}|{$action}|{$args_en}|$anchor|";
            /*
            if ($action == "clist") {
                echo "controller = $controller| action = $action|";
                echo "args = ";
                print_r($args);
                echo "url_list = ";
                print_r($url_list);
                echo "url_input = ";
                echo $url_input;
                exit();
            }
            */
            foreach ($url_list as $url) {
                if (substr($url, 0, strlen($url_input)) == $url_input) {
                    $url_item = explode("|", substr($url, strlen($url_input)));
                    if (TRUE == $GLOBALS['G_SP']['html']['safe_check_file_exists'] && TRUE != $force_no_check) {
                        if (!is_readable($url_item[1])) return FALSE;
                    }
                    return $url_item;
                }
            }
        }
        return FALSE;
    }

    public function getUrl_htmladv($controller = null, $action = null, $args = null, $anchor = null, $force_no_check = FALSE)
    {
        if (TRUE == $GLOBALS['G_SP']['html']["enabled_zxadv"]) {
            try {
                $sep = $GLOBALS['G_SP']['html']["sep"];
                $zxurl_array = array();
                if ($controller == "main" && in_array($action, array("index", "clist", "cdetail"))) {
                    $obj_ag = spDB($GLOBALS['G_SP']['db']["prefix"] . "articlestyle", "sid");
                    $zxroot = WEB_ROOT . ($GLOBALS['G_SP']['html']['file_root_name'] ? "/" . $GLOBALS['G_SP']['html']['file_root_name'] : "");
                    switch ($action) {
                        case "index":
                            $zxurl_array[] = $zxroot . "/index.html";
                            break;
                        case "clist":
                            if (!$id = intval($args["id"]))
                                throw new Exception("no list id");
                            if (!$column_rs = $obj_ag->find(array("sid" => $id, "frontdisplay" => 1)))
                                throw new Exception("no found column id: $id");
                            if ($column_rs["parentid"]) {
                                if (!$main_column_rs = $obj_ag->find(array("sid" => $column_rs["parentid"], "frontdisplay" => 1)))
                                    throw new Exception("no found parent column id: $column_rs[parentid]");
                                if ($args["pid"]) {
                                    $zxurl_add = $sep . $args["pid"];
                                }
                                if ($args["l"]) {
                                    $zxurl_add = $sep . "l" . $args["l"];
                                }
                                if ($args["f"]) {
                                    $zxurl_add = $sep . "f" . $args["f"];
                                }
                                if ($args["page"]) {
                                    $zxurl_addfile = $sep . $args["page"];
                                }
                                $zxurl_array[] = $zxroot . "/" . $main_column_rs["mark"] . $sep . $column_rs["mark"] . $zxurl_add . $sep . "index" . $zxurl_addfile . ".html";
                            } else {
                                $zxurl_array[] = $zxroot . "/" . $column_rs["mark"] . $sep . "index.html";
                            }
                            break;
                        case "cdetail":
                            $obj_article = spDB($GLOBALS['G_SP']['db']["prefix"] . "articles", "pid");
                            if (!$id = intval($args["id"]))
                                throw new Exception("no news id");
                            if (!$info_rs = $obj_article->findByPk($id))
                                throw new Exception("no found news id: $id");
                            $obj_ag = spDB($GLOBALS['G_SP']['db']["prefix"] . "articlestyle", "sid");
                            if (!$column_rs = $obj_ag->find(array("sid" => $info_rs['ptype'], "parentid <>" => 0), null, "sid, parentid, mark, sname, cinfo, ismetatitle, islist, ishits, isposttime, ispackage, iscato, keywords, description, freeother, freeother2, freeother3, linkfield, displaydetail"))
                                throw new Exception("no found column id: $info_rs[ptype]");
                            if (!$main_column_rs = $obj_ag->find(array("sid" => $column_rs['parentid'], "parentid" => 0)))
                                throw new Exception("no found main column id: $column_rs[parentid]");
                            $zxurl_array[] = $column_rs["islist"] ? $zxroot . "/" . $main_column_rs["mark"] . $sep . $column_rs["mark"] . $sep . "$id.html" : $zxroot . "/" . $main_column_rs["mark"] . $sep . $column_rs["mark"] . ".html";
                            break;
                    }
                    return $zxurl_array;
                }
            } catch (Exception $e) {
                //error continue
            }
        }
        if ($url_list = spAccess('r', 'sp_url_list')) {
            $url_list = explode("\n", $url_list);
            /*
            统一将传导过来的参数转化成字符串形式 start
            zx 2012-04-19
            */
            if (!empty($args)) {
                foreach ($args as $key => $val) {
                    $args[$key] = (string)$val;
                }
            }
            /*
            统一将传导过来的参数转化成字符串形式 end
            */
            $args_en = !empty($args) ? json_encode($args) : "";
            $url_input = "{$controller}|{$action}|{$args_en}|$anchor|";
            /*
            if ($action == "clist") {
                echo "controller = $controller| action = $action|";
                echo "args = ";
                print_r($args);
                echo "url_list = ";
                print_r($url_list);
                echo "url_input = ";
                echo $url_input;
                exit();
            }
            */
            foreach ($url_list as $url) {
                if (substr($url, 0, strlen($url_input)) == $url_input) {
                    $url_item = explode("|", substr($url, strlen($url_input)));
                    if (TRUE == $GLOBALS['G_SP']['html']['safe_check_file_exists'] && TRUE != $force_no_check) {
                        if (!is_readable($url_item[1])) return FALSE;
                    }
                    return $url_item;
                }
            }
        }
        return FALSE;
    }

    /**
     * 写入url的列表程序，在make生成页面后，将spUrl参数及页面地址写入列表中
     *
     * @param spurl spUrl的参数
     * @param baseuri URL地址对应的静态HTML文件访问地址
     *
     */
    public function setUrl($spurl, $baseuri, $realfile)
    {
        @list($controller, $action, $args, $anchor) = $spurl;
        /*
        统一将传导过来的参数转化成字符串形式 start
        zx 2012-04-19
        */
        if (!empty($args)) {
            foreach ($args as $key => $val) {
                $args[$key] = (string)$val;
            }
        }
        /*
        统一将传导过来的参数转化成字符串形式 end
        */
        $this->clear($controller, $action, $args, $anchor, FALSE);
        $args = !empty($args) ? json_encode($args) : '';
        $url_input = "{$controller}|{$action}|{$args}|{$anchor}|{$baseuri}|{$realfile}";
        if ($url_list = spAccess('r', 'sp_url_list')) {
            spAccess('w', 'sp_url_list', $url_list . "\n" . $url_input);
        } else {
            spAccess('w', 'sp_url_list', $url_input);
        }
    }

    /**
     * 清除静态文件
     *
     * @param controller    需要清除HTML文件的控制器名称
     * @param action    需要清除HTML文件的动作名称，默认为清除该控制器全部动作产生的HTML文件
     * 如果设置了action将仅清除该action产生的HTML文件
     *
     * @param args    传递的参数，默认为空将清除该动作任何参数产生的HTML文件
     * 如果设置了args将仅清除该动作执行参数args而产生的HTML文件
     *
     * @param anchor    跳转锚点，默认为空将清除该动作任何锚点产生的HTML文件
     * 如果设置了anchor将仅清除该动作跳转到锚点anchor产生的HTML文件
     *
     * @param delete_file    是否删除物理文件，FALSE将只删除列表中该静态文件的地址，而不删除物理文件。
     */
    public function clear($controller, $action = null, $args = FALSE, $anchor = '', $delete_file = TRUE)
    {
        if ($url_list = spAccess('r', 'sp_url_list')) {
            $url_list = explode("\n", $url_list);
            $re_url_list = array();
            if (null == $action) {
                $prep = "{$controller}|";
            } elseif (FALSE === $args) {
                $prep = "{$controller}|{$action}|";
            } else {
                $args = !empty($args) ? json_encode($args) : '';
                $prep = "{$controller}|{$action}|{$args}|{$anchor}|";
            }
            foreach ($url_list as $url) {
                if (substr($url, 0, strlen($prep)) == $prep) {
                    $url_tmp = explode("|", $url);
                    $realfile = $url_tmp[5];
                    if (TRUE == $delete_file) @unlink($realfile);
                } else {
                    $re_url_list[] = $url;
                }
            }
            spAccess('w', 'sp_url_list', join("\n", $re_url_list));
        }
    }


    /**
     * 清除全部静态文件
     *
     * @param delete_file    是否删除物理文件，FALSH将只删除列表中该静态文件的地址，而不删除物理文件。
     */
    public function clearAll($delete_file = FALSE)
    {
        if (TRUE == $delete_file) {
            if ($url_list = spAccess('r', 'sp_url_list')) {
                $url_list = explode("\n", $url_list);
                foreach ($url_list as $url) {
                    $url_tmp = explode("|", $url);
                    $realfile = $url_tmp[5];
                    @unlink($realfile);
                }
            }
        }
        spAccess('c', 'sp_url_list');
    }
}